package cn.org.guhao.practice.redis.config;

import info.boruisi.platform.redis.template.BigDecimalRedisTemplate;
import info.boruisi.platform.redis.template.IntegerRedisTemplate;
import org.springframework.boot.env.RandomValuePropertySource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;

/**
 * Redis Configuration
 * @author guhao 
 */
@Configuration
@EnableRedisRepositories
public class RedisConfig {

    @Bean
    RedisTemplate redisTemplate(RedisConnectionFactory factory){
        RedisTemplate redisTemplate = new RedisTemplate();
        redisTemplate.setConnectionFactory(factory);
        return redisTemplate;
    }

    @Bean
    BigDecimalRedisTemplate bigDecimalRedisTemplate(RedisConnectionFactory factory){
        BigDecimalRedisTemplate template = new BigDecimalRedisTemplate();
        template.setConnectionFactory(factory);
        return template;
    }

    @Bean
    IntegerRedisTemplate integerRedisTemplate(RedisConnectionFactory factory){
        IntegerRedisTemplate template = new IntegerRedisTemplate();
        template.setConnectionFactory(factory);
        return template;
    }

    /**
     * 引入随机数组件
     * @return
     */
    @Bean
    public RandomValuePropertySource randomValuePropertySource(){
        return new RandomValuePropertySource("RedPacketRandom");
    }

}
